package com.freemyleft.left.zapp.selectimage;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;



import com.freemyleft.left.zapp.selectimage.activity.CameraActivity;
import com.freemyleft.left.zapp.selectimage.listener.CameraListener;

/**
 * Created by Administrator on 2017/6/7.
 */
public class CameraUtils {
    private Activity mActivity;
    private CameraListener mCameraListener;
    private boolean mIsCut = false;//是否裁剪
    private int mCutWidth = 0;
    private int mCutHight = 0;

    public CameraUtils(Activity activity){
        mActivity = activity;
    }
    public CameraUtils setOnCameraListener(CameraListener cameraListener){
        mCameraListener = cameraListener;
        return this;
    }
    public void start(){
        String[] strings = new String[3];
        strings[0] = Manifest.permission.READ_EXTERNAL_STORAGE;
        strings[1] = Manifest.permission.WRITE_EXTERNAL_STORAGE;
        strings[2] = Manifest.permission.CAMERA;
        if (new PermissionsUtils(mActivity).getPermissionLisr(strings)) {
            return;
        }
        if (mCameraListener != null){
            CameraActivity.setOnCameraListener(mCameraListener);
        }
        Intent intent = new Intent(mActivity, CameraActivity.class);
        if (mIsCut){
            intent.putExtra("isCut", mIsCut);
            intent.putExtra("cut_width", mCutWidth);
            intent.putExtra("cut_hight", mCutHight);
        }
        mActivity.startActivity(intent);
    }

    /**是否裁剪*/
    public CameraUtils setCut(int cutWidth, int cutHight){
        mCutWidth = cutWidth;
        mCutHight = cutHight;
        mIsCut = true;
        return this;
    }
}
